import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'

Vue.config.productionTip = false;

//导入并使用全局方法和变量
import Global from './Global';
Vue.use(Global);

//注册全局组件
import MyList from "./components/MyList.vue"
Vue.component(MyList.name, MyList);
//注册全局组件
import MyLogin from "./components/MyLogin.vue"
Vue.component(MyLogin.name, MyLogin);

//全局指令
/*Vue.directive('myShow', {
    bind(el,binding,vnode,oldVnode){
        console.log("自定义指令中的el===>",el);
        console.log("自定义指令中的binding===>",binding);

        el.style.display = binding.value?"block":"none"

    },
    update(el,binding,vnode,oldVnode){

        console.log("自定义指令中的updateBinding===>",binding);
        el.style.display = binding.value?"block":"none"
    }
});*/

//全局指令
Vue.directive('myShow',function (el, binding,vnode) {
    // el.style.display = binding.value?"block":"none"
    console.log(vnode)
    if(binding.value){

    }else {
        el.parentNode.removeChild(el);
    }


});

// 相对时间过滤器,把时间戳转换成时间
// 格式: 2020-02-25 21:43:23
Vue.filter('dateFormat', (dataStr) => {
    let time = new Date(dataStr);
    function timeAdd0 (str) {
        if (str < 10) {
            str = '0' + str;
        }
        return str;
    }
    let y = time.getFullYear();
    let m = time.getMonth() + 1;
    let d = time.getDate();
    let h = time.getHours();
    let mm = time.getMinutes();
    let s = time.getSeconds();
    return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) + ' ' + timeAdd0(h) + ':' + timeAdd0(mm) + ':' + timeAdd0(s);
});

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
